#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys
from PyQt4 import QtGui, QtCore


class FundamentalWidgets(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        self.setGeometry(300, 300, 300, 300)
        self.setWindowTitle("FundamentalWidgets")
        grid = QtGui.QGridLayout()
        grid.setSpacing(10)

        #QLabel
        self.qlabel1 = QtGui.QLabel('is a label')
        grid.addWidget(self.qlabel1)

        print self.qlabel1.text()
        self.qlabel1.setText('&&Eew text')
        print self.qlabel1.text()
        #self.qlabel1.setNum(1)
        #self.qlabel1.setPixmap(QtGui.QPixmap('icon.png'))
        #self.qlabel1.clear()

        #QLineEdit
        self.qlineedit1 = QtGui.QLineEdit('put you words')
        grid.addWidget(self.qlineedit1)
        self.qlineedit2 = QtGui.QLineEdit('password')
        self.qlineedit2.setEchoMode(QtGui.QLineEdit.PasswordEchoOnEdit)
        #self.qlineedit2.setEchoMode(QtGui.QLineEdit.Password)
        grid.addWidget(self.qlineedit2)
        self.qlineedit3 = QtGui.QLineEdit('sdf')
        grid.addWidget(self.qlineedit3)

        self.qlineedit1.setText('new')
        print self.qlineedit1.text()
        print self.qlineedit2.text()
        #print self.qlineedit1.maxLength()
        print self.qlineedit1.insert('sss')
        #print self.qlineedit1.maxLength()
        self.qlineedit1.setReadOnly(True)
        #self.qlineedit1.setEnabled(False)

        self.qlineeditn1 = QtGui.QLineEdit('firstnum')
        grid.addWidget(self.qlineeditn1)
        self.qlineeditn2 = QtGui.QLineEdit('secondnum')
        grid.addWidget(self.qlineeditn2)
        self.qlineeditret = QtGui.QLineEdit('result')
        grid.addWidget(self.qlineeditret)

        #QPushButton
        self.qbutton1 = QtGui.QPushButton('&Bt1')
        grid.addWidget(self.qbutton1)

        self.qbuttoncacl = QtGui.QPushButton('Cacl')
        grid.addWidget(self.qbuttoncacl)


        self.setLayout(grid)

        self.connect(self.qbutton1, QtCore.SIGNAL('clicked()'), self.bt1click)
        self.connect(self.qbuttoncacl, QtCore.SIGNAL('clicked()'), self.btcacl)

    def bt1click(self):
        self.qlineedit3.setText('WEL' + self.qlineedit3.text())

    def btcacl(self):
        if len(self.qlineeditn1.text()) != 0:
            a = int(self.qlineeditn1.text())
        else:
            a = 0
        if len(self.qlineeditn2.text()) != 0:
            b = int(self.qlineeditn2.text())
        else:
            b = 0
        sum = a + b
        self.qlineeditret.setText("ret: " + str(sum))


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = FundamentalWidgets()
    main.show()
    sys.exit(app.exec_())